<template>
  <a-config-provider :locale="locale">

    <router-view />
  </a-config-provider>
</template>
<script>
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');
import { reactive, toRefs, ref, defineComponent, provide } from "vue";
export default defineComponent({
  name: "App",
  setup () {
    const path = ref('/index/home')
    const crumb = ref(['后台首页', '欢迎页'])
    provide('path', path)
    provide('crumb', crumb)
    const router = useRouter()
    //全局导航守卫
    router.beforeEach((to, from, next) => {
      if (
        to.path == "/login" ||
        to.path == "/404"
      ) {
        next();
      } else {
        //  后期请求接口了 ，解开
        // let token = sessionStorage.tokenId;
        let token = sessionStorage.token;
        crumb.value = to.meta.crumb
        if (token) {
          path.value = to.matched.map((v, i) => {
            if (i) {
              return v.path
            }
          })
          next();
        } else {
          message.warning('您的身份已过期，请重新登录')
          next({ path: "/login" });
        }
      }
    });
    return {
      locale: zhCN,
    };
  },
});
</script>
<style lang="scss">
* {
  margin: 0;
  padding: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: white;
  width: 100%;
  height: 100%;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
